/**
 * zmn产品模块-产品列表
 * @author tanghongjun
 * @since 2018/10/18
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        height: 'full-189'
    });
    laypage.render(zmnPage.laypageOptions(json));

    //【表格左上侧工具栏监听】
    table.on("toolbar(zmn-table)", function (obj) {
        if(obj.event == "del") {
            var ids = zmnPage.layTabldIds(obj, "relateId");
            if(ids.length === 0){ return layer.alert("请选择至少一条数据！"); }
            layer.confirm('确认移除渠道配置吗？', function() {
                zmnPage.ajaxSimple("/msg/temp/conf/delChannelConfig", { ids: ids.join(",")}, 1000);
            });
            return;
        }
        if (obj.event == "select") {
            zmnLayUtil.openIframeCustom(layer, "/msg/temp/conf/selectChannel.action?templateId="+json.templateId, {
                title: '选择渠道',
                area: ['70%', '70%']
            });
        }
    });

    //【表格右侧工具栏监听】
    table.on('tool(zmn-table)', function (obj) {
        var id = obj.data.relateId;
        if(obj.event == "del") {
            layer.confirm('确认移除渠道配置吗？', function() {
                zmnPage.ajaxSimple("/msg/temp/conf/delChannelConfig", { ids: id}, 1000);
            });
            return;
        }
    });

    //对外暴露的接口
    exports('msg_template_config_channel_list', {});
});
